﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utility1;

namespace eDream.Page
{
    public partial class Sanpham_damua : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int month = DateTime.Now.Month;
                int year = DateTime.Now.Year;
                DateTime lastday = Utility1.Utils.GetLastDayOfMonth(year, month);
                DateTime dtfrom = Utility1.Utils.GetfirstDayOfMonth(year, month);
                dteFrom.Date = dtfrom;
                dteTo.Date = lastday;
            }
        }

        void Bindata_Log(int id)
        {
            
            try
            {

                Xuly xl = new Xuly();
                SqlParameter[] arrParam =
                {
                    new SqlParameter("@dateFrom1", System.Data.SqlDbType.DateTime),
                    new SqlParameter("@dateTo1", System.Data.SqlDbType.DateTime),
                    new SqlParameter("@IDUser", System.Data.SqlDbType.Int),
                    new SqlParameter("@flag", System.Data.SqlDbType.Int)
                 
                };
                arrParam[0].Value = dteFrom.Date;
                arrParam[1].Value = dteTo.Date;
                arrParam[2].Value = id;
                arrParam[3].Value = int.Parse(cbxTrangthai.Value.ToString());
               

                DataTable dt = xl.ExcuteStoreTable("sp_getAll_donhang",arrParam);
                grvDonhang.DataSource = dt;
                grvDonhang.DataBind();
                grvDonhang.SettingsBehavior.AllowSort = true;

                grvDonhang.Settings.ShowFilterRow = true;
                 
            }
            catch (Exception) { }
           
        }

        protected void grvDonhang_Load(object sender, EventArgs e)
        {
            try
            {
                UserDB user_obj = (UserDB)Session[Global.SESS_USER];
                Bindata_Log(user_obj.ID);
            }
            catch (Exception) { }
        }

        protected void btnTim_Click(object sender, EventArgs e)
        {
            try
            {
            UserDB user_obj = (UserDB)Session[Global.SESS_USER];
            Bindata_Log(user_obj.ID);
            }
             catch (Exception) { }
        }
    }
}